package com.tyqx.hashchainbiz.service.impl;

import com.tyqx.hashchainbean.module.SystemConfig;
import com.tyqx.hashchainbiz.service.SystemConfigService;
import com.tyqx.hashchaindao.mapper.SystemConfigMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service("systemConfigService")
public class SystemConfigServiceImpl implements SystemConfigService {

    @Resource
    private SystemConfigMapper systemConfigMapper;

    @Override
    public Integer addSystemConfig(SystemConfig systemConfig) throws Exception {
        Date currentDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date createTime = sdf.parse(sdf.format(currentDate));
        systemConfig.setCreateTime(createTime);
        return systemConfigMapper.addSystemConfig(systemConfig);
    }

    @Override
    public SystemConfig selectSystemConfigByKey(String configKey) {
        return systemConfigMapper.selectSystemConfigByKey(configKey);
    }

    @Override
    public Integer updateConfigValueByKey(SystemConfig systemConfig)throws Exception {
        Date currentDate = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date updateTime = sdf.parse(sdf.format(currentDate));
        systemConfig.setUpdateTime(updateTime);
        return systemConfigMapper.updateConfigValueByKey(systemConfig);
    }
}
